home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 20
/
Cream of the Crop 20 (Terry Blount) (1996).iso
/
os2
/
sysb091a.zip
/
sysbench
/
src
/
pmb_sieve.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-05-23
|
20KB
|
742 lines
/****************** Start NSIEVE C Source Code ************************/
/****************************************************************/
/* NSIEVE */
/* C Program Source */
/* Sieve benchmark for variable sized arrays */
/* Version 1.2b, 26 Sep 1992 */
/* Al Aburto (aburto@marlin.nosc.mil) */
/* ('ala' on BIX) */
/* */
/* */
/* This Sieve of Eratosthenes program works with variable size */
/* arrays. It is a straight forward extension of the original */
/* Gilbreath version ( Gilbreath, Jim. "A High-Level Language */
/* Benchmark." BYTE, September 1981, p. 180, and also Gilbreath,*/
/* Jim and Gary. "Eratosthenes Revisited: Once More Through the */
/* Sieve." BYTE January 1983, p. 283 ). Unlike the Sieve of */
/* Gilbreath, NSIEVE uses register long variables, pointers,and */
/* large byte arrays via 'malloc()'. Maximum array size is */
/* currently set at 2.56 MBytes but this can be increased or */
/* decreased by changing the program LIMIT constant. NSIEVE */
/* provides error checking to ensure correct operation. Timer */
/* routines are provided for several different systems. NSIEVE */
/* results won't generally agree with the Gilbreath Sieve */
/* results because NSIEVE specifically uses register long */
/* variables. NSIEVE, and Sieve, are programs designed */
/* specifically to generate and printout prime numbers (positive*/
/* integers which have no other integral factor other than */
/* itself and unity, as 2,3,5,7,11, ... ). NSIEVE does not */
/* conduct the 'typical' instructions one might expect from the */
/* mythical 'typical program'. NSIEVE results can be used to */
/* gain a perspective into the relative performance of different*/
/* computer systems, but they can not be used in isolation to */
/* categorize the general performance capabilities of any */
/* computer system (no single benchmark program currently can do*/
/* this). */
/* */
/* The program uses a maximum array size of 2.56 MBytes. You can*/
/* increase or lower this value by changing the 'LIMIT' define */
/* from 9 to a higher or lower value. Some systems (IBM PC's */
/* and clones) will be unable to work beyond 'LIMIT = 3' which */
/* corresponds to an array size of only 40,000 bytes. Be careful*/
/* when specifying LIMIT > 3 for these systems as the system may*/
/* crash or hang-up. Normally NSIEVE will stop program execution*/
/* when 'malloc()' fails. */
/* */
/* The maximum array size is given by: */
/* size = 5000 * ( 2 ** LIMIT ). */
/* */
/* The array 'Number_Of_Primes[LIMIT]' is intended to hold the */
/* correct number of primes found for each array size up to */
/* LIMIT = 20, but the array is only currently defined up to */
/* LIMIT = 13. */
/* */
/* Program outputs to check for correct operation: */
/* Array Size LIMIT Primes Found Last Prime */
/* (Bytes) */
/* 8191 0 1899 16381 */
/* 10000 1 2261 19997 */
/* 20000 2 4202 39989 */
/* 40000 3 7836 79999 */
/* 80000 4 14683 160001 */
/* 160000 5 27607 319993 */
/* 320000 6 52073 639997 */
/* 640000 7 98609 1279997 */
/* 1280000 8 187133 2559989 */
/* 2560000 9 356243 5119997 */
/* 5120000 10 679460 10239989 */
/* 10240000 11 1299068 20479999 */
/* 20480000 12 2488465 40960001 */
/* 40960000 13 4774994 81919993 */
/* 81920000 14 ------- --------- */
/****************************************************************/
/****************************************************/
/* Example Compilation: */
/* (1) UNIX Systems: */
/* cc -O -DUNIX nsieve.c -o nsieve */
/* cc -DUNIX nsieve.c -o nsieve */
/****************************************************/
#include <stdio.h>
#ifndef vax
#include <stdlib.h>
#endif
#include <math.h>
/***********************************************/
#define LIMIT 8 /* You may need to change this to '3' for PC's */
/* and Clones or you can experiment with higher*/
/* values, but '13' is currently the max. */
/***********************************************/
/***************************************************************/
/* Timer options. You MUST uncomment one of the options below */
/* or compile, for example, with the '-DUNIX' option. */
/***************************************************************/
/* #define Amiga */
/* #define UNIX */
/* #define UNIX_Old */
/* #define VMS */
/* #define BORLAND_C */
/* #define MSC */
/* #define MAC */
/* #define IPSC */
/* #define FORTRAN_SEC */
/* #define GTODay */
/* #define CTimer */
/* #define UXPM */
#ifdef Amiga
#include <exec/types.h>
#include <ctype.h>
#endif
#ifdef BORLAND_C
#include <ctype.h>
#include <dos.h>
#endif
#ifdef MSC
#include <ctype.h>
#endif
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
#define INCL_DOSMISC
#include <os2.h>
static double nulltime,runtime,TimeArray[4];
static double reftime,adj_time,emips;
static double hmips,lmips,smips[21];
static long L_Prime,N_Prime; /* Last Prime and Number of Primes Found */
static long ErrorFlag;
static long Number_Of_Primes[21]; /* List of Correct Number of Primes for */
/* each sieve array size. */
static long NLoops[21];
static SIEVE(long m,long n,long p);
int sieve_time(double* p);
void err(char* s);
double pmb_sieve(void)
{
long i,j,k,p;
double sumtime;
/*
printf("\n Sieve of Eratosthenes (Scaled to 10 Iterations)\n");
printf(" Version 1.2b, 26 Sep 1992\n\n");
printf(" Array Size Number Last Prime Linear");
printf(" RunTime MIPS\n");
printf(" (Bytes) of Primes Time(sec)");
printf(" (Sec)\n");
*/
/*******************************/
/* Number of Array Size */
/* Primes Found (Bytes) */
Number_Of_Primes[0] = 1899; /* 8191 */
Number_Of_Primes[1] = 2261; /* 10000 */
Number_Of_Primes[2] = 4202; /* 20000 */
Number_Of_Primes[3] = 7836; /* 40000 */
Number_Of_Primes[4] = 14683; /* 80000 */
Number_Of_Primes[5] = 27607; /* 160000 */
Number_Of_Primes[6] = 52073; /* 320000 */
Number_Of_Primes[7] = 98609; /* 640000 */
Number_Of_Primes[8] = 187133; /* 1280000 */
Number_Of_Primes[9] = 356243; /* 2560000 */
Number_Of_Primes[10]= 679460; /* 5120000 */
Number_Of_Primes[11]= 1299068; /* 10240000 */
Number_Of_Primes[12]= 2488465; /* 20480000 */
Number_Of_Prime